<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="平台" prop="platform">
        <el-input
          v-model="queryParams.platform"
          placeholder="请输入平台"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    
 

    <el-table v-loading="loading" :data="configInfoList">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="认证类型" align="center" prop="type" />
      <el-table-column label="平台" align="center" prop="platform" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="备注信息" align="center" prop="remarkInfo" />
      <el-table-column label="请求url" align="center" prop="requestUrl" />
      <el-table-column label="查询url" align="center" prop="queryUrl" />
      <el-table-column label="通知url" align="center" prop="noticeUrl" />

    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户认证配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="平台" prop="platform">
          <el-input v-model="form.platform" placeholder="请输入平台" />
        </el-form-item>
        <el-form-item label="备注信息" prop="remarkInfo">
          <el-input v-model="form.remarkInfo" placeholder="请输入备注信息" />
        </el-form-item>
        <el-form-item label="scene_id" prop="sceneId">
          <el-input v-model="form.sceneId" placeholder="请输入scene_id" />
        </el-form-item>
        <el-form-item label="product_code" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入product_code" />
        </el-form-item>
        <el-form-item label="product_model" prop="productModel">
          <el-input v-model="form.productModel" placeholder="请输入product_model" />
        </el-form-item>
        <el-form-item label="ext_data" prop="extData">
          <el-input v-model="form.extData" placeholder="请输入ext_data" />
        </el-form-item>
        <el-form-item label="编号" prop="appCode">
          <el-input v-model="form.appCode" placeholder="请输入编号" />
        </el-form-item>
        <el-form-item label="key" prop="appKey">
          <el-input v-model="form.appKey" placeholder="请输入key" />
        </el-form-item>
        <el-form-item label="密钥" prop="appSercret">
          <el-input v-model="form.appSercret" placeholder="请输入密钥" />
        </el-form-item>
        <el-form-item label="公钥" prop="pubKey">
          <el-input v-model="form.pubKey" placeholder="请输入公钥" />
        </el-form-item>
        <el-form-item label="私钥" prop="priKey">
          <el-input v-model="form.priKey" placeholder="请输入私钥" />
        </el-form-item>
        <el-form-item label="请求url" prop="requestUrl">
          <el-input v-model="form.requestUrl" placeholder="请输入请求url" />
        </el-form-item>
        <el-form-item label="查询url" prop="queryUrl">
          <el-input v-model="form.queryUrl" placeholder="请输入查询url" />
        </el-form-item>
        <el-form-item label="通知url" prop="noticeUrl">
          <el-input v-model="form.noticeUrl" placeholder="请输入通知url" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listConfigInfo, getConfigInfo, delConfigInfo, addConfigInfo, updateConfigInfo } from "@/api/member/configInfo";

export default {
  name: "ConfigInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户认证配置表格数据
      configInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        platform: null,
        status: null,
        remarkInfo: null,
        sceneId: null,
        productCode: null,
        productModel: null,
        extData: null,
        appCode: null,
        appKey: null,
        appSercret: null,
        pubKey: null,
        priKey: null,
        requestUrl: null,
        queryUrl: null,
        noticeUrl: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户认证配置列表 */
    getList() {
      this.loading = true;
      listConfigInfo(this.queryParams).then(response => {
        this.configInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        platform: null,
        status: null,
        remarkInfo: null,
        sceneId: null,
        productCode: null,
        productModel: null,
        extData: null,
        appCode: null,
        appKey: null,
        appSercret: null,
        pubKey: null,
        priKey: null,
        requestUrl: null,
        queryUrl: null,
        noticeUrl: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户认证配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getConfigInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户认证配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateConfigInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addConfigInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户认证配置编号为"' + ids + '"的数据项？').then(function() {
        return delConfigInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('member/configInfo/export', {
        ...this.queryParams
      }, `configInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
